<?php
/**
 * This page maps RSS Feeds from the mod_rewrite URL to a file in the site
 * Found at /rss/([a-zA-Z0-9_]+).rss
 * It maps ([a-zA-Z0-9_]+).rss to rss-feeds/(.*?).php based on an array key.
 * TODO: Move the array key to database, to enable/disable on demand?
 * 
 * This page can only be accessed using mod_rewrite.
 * This page has no access to the templating system
 */

    $_ECLIPSEMDE = array();
    // Disable Templating System
    $_ECLIPSEMDE['TEMPLATING'] = false;
    
    require_once('../SiteIncludes.GLOBAL.php');
    // Include this to generate the feeds
    require_once($_ECLIPSEMDE['ROOT_WD'].'core/rss/RSSFeed.php');
    
    $_LIBDEBUG->silence();
    
    // Global Copyright Notice for all feeds:
    $copyrightNotice = "Copyright Eclipse MDE Tool.";
    
    if(EclipseMDE::runningOnMod_Rewrite() === false) {
	// Security Guard, Do Not Let This be accessed by any other means than mod_rewrite
	$gVAR['e'] = '403';
	require_once('error_handler.php');
    }
    
    
    /*
     * Array Layout:
     * 
     * Key: Alias /rss/[feedname]
     * Val: Script Name (should be present in the rss-feeds directory!)
     */
    $VALID_RSS_FEEDS = array(
	'newest' => 'newest.php'
    );
    
    // Check Alias is set:
    // Check The Alias exists in the array above
    // Check the file exists
    // All this is true? - Include the file to render the feed!
    if(isset($gVAR['alias']) && 
	    array_key_exists($gVAR['alias'], $VALID_RSS_FEEDS) &&
	    file_exists($_ECLIPSEMDE['RSS_PATH'].$VALID_RSS_FEEDS[$gVAR['alias']])) {
	ob_clean(); // Delete the output buffer
	header('Content-type: application/rss+xml; charset=ISO-8859-1');
	require_once($_ECLIPSEMDE['RSS_PATH'].$VALID_RSS_FEEDS[$gVAR['alias']]);
    } elseif(isset($gVAR['alias']) === true && $gVAR['alias'] === 'tool' && isset($gVAR['tool'])) {
	require_once($_ECLIPSEMDE['RSS_PATH'].'tool_rss_feed.php');
	
    } else {
	$gVAR['e'] = '404';
	require_once('error_handler.php');
    }
    
?>
